<?php
/**
 * 宝贝生日祝福类
 * @author zhanghui
 * @create_date 2008-02-29
 */
class BirthdayBless{
	
	function __construct(){}
	function __destruct(){}
	
	/**增加生日祝福
	 * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,postid,title,content,writer_id,writer_name,create_date
     */
	function addBirthdayBless($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_birthday_bless";
		$str_query .= " set";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= ",title='{$arr_input['title']}'";
		$str_query .= ",content='{$arr_input['content']}'";
		$str_query .= ",writer_id={$arr_input['writer_id']}";
		$str_query .= ",writer_name='{$arr_input['writer_name']}'";
		$str_query .= ",create_date='".$conn->getCurrentTime()."'";
		
		$conn->executeQuery($str_query);
	}
	
	/**删除生日祝福
	 * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,postid,title,content,writer_id,writer_name,create_date
     */
	function deleteBirthdayBless($conn,$arr_input){
		$str_query = "delete from";
		$str_query .= " baby_birthday_bless";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		if(isset($arr_input['postid'])){
			$str_query .= " and postid={$arr_input['postid']}";
		}	
		
		$conn->executeQuery($str_query);
	}
	
	/**获取生日祝福
	 * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,postid,title,content,writer_id,writer_name,create_date
     *			baby_id, 			[0]<br>
     *			postid, 		    [1]<br>
     *			title, 		    	[2]<br>
     *			content, 			[3]<br>
     *			writer_id, 			[4]<br>
     *			writer_name, 		[5]<br>
     *			create_date, 		[6]<br>
     */
	function getBirthdayBlessList($conn,$arr_input,$limit = null){
		$str_query = "select";
		if(isset($arr_input['cnt'])){
			$str_query .= " count(1)";
		}else{
			$str_query .= " baby_id";
		    $str_query .= ",postid";
		    $str_query .= ",title";
		    $str_query .= ",content";
		    $str_query .= ",writer_id";
		    $str_query .= ",writer_name";
		    $str_query .= ",create_date";
		}
		$str_query .= " from";
		$str_query .= " baby_birthday_bless";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		if(isset($arr_input['postid'])){
			$str_query .= " and postid={$arr_input['postid']}";
		}
		if(isset($arr_input['orderby'])){
			$str_query .= " order by {$arr_input['orderby']}";
		}		
		if($limit!=null){
			$str_query .= " {$limit}";
		}
		
		$arr_output = $conn->selectQuery($str_query);
		return $arr_output;
	}
}

?>